import { Random } from "mockjs"; // 导出随机函数

let login = (req) =>  {
  // req是一个请求对象，包含: url，type和body属性
  return {
    code: 200,
    message: "OK",
    data: {
      username: Random.cname(),
      token: Random.guid(),
    }
  };
}

let getUserInfo = (req) => {
  let params = JSON.parse(req.body);
  console.log("用户信息请求对象：", params);

  if (params.token !== "123456") {
    return {
      code: 400,
      message: "Invalid token.",
      data: {}
    };
  }

  return {
    code: 200,
    message: "OK",
    data: {
      nickname: Random.cname(),
      avatar: Random.image('200X200', Random.color(),"🍁"),
      slogan: Random.csentence(),
    }
  };
}

let logout = (req) => {
  return {
    code: 200,
    message: "OK",
    data: {
      status: 0,
    }
  };
}

export default {
  login,
  getUserInfo,
  logout
};
